package baseObjectContract;

import assertTools.DecoratorTools;
import baseObject.IBrickBreaker;
import baseObjectDecorator.BrickBreakerDecorator;

public class BrickBreakerContract extends BrickBreakerDecorator{
	public IBrickBreaker brickBreaker;

	public BrickBreakerContract(IBrickBreaker brickBreaker) {
		super(brickBreaker);
		this.brickBreaker = brickBreaker;
	}
	
	public void init(int xMax, int yMax){
		DecoratorTools.checkPre(xMax > 0);
		DecoratorTools.checkPre(yMax > 0);
		super.init(xMax, yMax);
		DecoratorTools.checkPost(super.getXMAX() == xMax);
		DecoratorTools.checkPost(super.getYMAX() == yMax);
		DecoratorTools.checkPost(super.getPlayerDirection() == IBrickBreaker.TMove.NONE);
		DecoratorTools.checkPost(super.isFinished() == IBrickBreaker.TFinished.NO);
	}
	
	public void movePaddle(TMove tMove) {
		int xAtOld = super.getPaddle().getX();
		super.movePaddle(tMove);
	
		if(tMove == TMove.LEFT)
			DecoratorTools.checkPost(xAtOld == super.getPaddle().getX() - 1);
		
		if(tMove == TMove.RIGHT)
			DecoratorTools.checkPost(xAtOld == super.getPaddle().getX() + 1);
	}
}
